package com.cloudree.gllib;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;

import com.cloudree.gllib.render.BaseRender;
import com.cloudree.gllib.surface.BaseGLSurface;
import com.kvin.toolkit.activity.OnBindInit;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/8/1.
 */
public class BaseActivity extends AppCompatActivity implements View.OnClickListener, OnBindInit {
    protected BaseGLSurface mSurface;
    protected BaseRender mRender;
    protected FragmentManager mManager;
    protected ArrayList<Fragment> fragments;
    protected int index;
    protected OnTouchListener mTouchListener;

    /**
     * touch listener
     *
     * @param mTouchListener
     */
    public void setTouchListener(OnTouchListener mTouchListener) {
        this.mTouchListener = mTouchListener;
    }

    private boolean initialized;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initialized = false;
    }


    @Override
    protected void onStart() {
        super.onStart();
        if (!initialized) {
            initialized = true;
            init();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mSurface != null) {
            mSurface.onResume();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mSurface != null) {
            mSurface.onPause();
        }
    }

    /**
     * return a context
     */
    public Activity getActivity() {
        return this;
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void init() {

    }

    @Override
    public void initNav() {

    }

    @Override
    public void initDialog() {

    }

    @Override
    public void loadingData() {

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return mTouchListener == null ? super.onTouchEvent(event) : mTouchListener.onTouch(event);
    }

    /**
     * pass touch event
     */
    public interface OnTouchListener {
        boolean onTouch(MotionEvent event);
    }
}
